function Util() {}
	Util.strToBytes = function(str) {
		var arr = [];
		for (var i = 0, j = str.length; i < j; i += 3) {
			var num = parseInt(str.substring(i, i + 2), 16);
			arr.push(num);
		}
		return new Uint8Array(arr);
	}
	Util.padLeft = function(val, len, charStr) {
		var s = val + '';
		return new Array(len - s.length + 1).join(charStr, '') + s;
	}
	Util.padRight = function(val, len, charStr) {
		var s = val + '';
		return s + new Array(len - s.length + 1).join(charStr, '');
	}
	Util.bytesToStr = function(bytes) {
		var str = "";
		for (var i = 0; i < bytes.length; i++) {
			str += this.byteToStr(bytes[i]) + " ";
		}
		return str;
	}
	Util.byteToStr = function(b) {
		var str = b.toString(16).toUpperCase();
		if (str.length < 2) str = '0' + str;
		return str;
	}

	Util.sumCheck = function(bytes, start, end) {
		var sum = 0;
		for (var i = start; i <= end; i++) {
			sum = (sum + bytes[i]) & 0xFF;
		}
		return sum
	}

	// var aa = Util.strToBytes("68 16");
	// var bb = new Uint8Array(10);
	// bb.set(aa);
	// bb[2] = 0x21;
	// var cc = bb.subarray(0, 3); //结束的索引将不会被包括
	// console.log(Util.bytesToStr(cc));

	class U8a extends Uint8Array {
		constructor(arr) {
			super(arr);
			this.pos = 0;
			this.view = new DataView(this.buffer);
		}
		getData(p) {
			return this.view.getUint8(this.pos++);
		}
		getPos() {
			return this.pos;
		}
	}

	// const u = new U8a([0x11, 253]);
	// console.log("U8a " + u.getData()); 
	// console.log("U8a " + u.getData()); 


	function XBuffer(arr) {
		this.pos = 0;
		this.bytes = new Uint8Array(arr);
	}
	XBuffer.prototype.getBin1 = function() {
		var ret = this.bytes[this.pos];
		this.pos++;
		return ret;
	}
	XBuffer.prototype.get = function(pos) {
		return this.bytes[pos];
	}
	// var dd = new XBuffer(Util.strToBytes(
	// 	"68 42 00 42 00 68 88 11 01 0B 00 21 0A 69 00 00 01 0B 11 01 0B 00 62 16 00 01"));
	// console.log("xbuffer[0]=" + dd.getBin1().toString(16));
	// console.log("xbuffer[1]=" + dd.getBin1().toString(16));

	function UpGw() {
		this.MIN_PACKET_LEN = 16;
		this.MAX_PACKET_LEN = 1024;
		this.HEAD_CHAR = 0x68;
		this.END_CHAR = 0x16;

		this.LEN_POS = 1;
		this.ADDR_POS = 2;
		this.HEAD_POS = 5;
		this.CC_POS = 6;
		this.DATA_LEN_POS = 10;
		this.SEQ_POS = 13;
		this.DATA_POS = 14;
	}
	UpGw.prototype.searchValid = function(buffer, len) {
		if (len < this.MIN_PACKET_LEN) return null;
		for (i = 0; i <= len - this.MIN_PACKET_LEN; i++) {
			if ((buffer[i + this.CC_POS] >> 7) == 1 &&
				buffer[i] == this.HEAD_CHAR &&
				buffer[i + this.HEAD_POS] == this.HEAD_CHAR) {
				var dataLen = (buffer[i + this.LEN_POS] >> 2) + buffer[i + 1 + this.LEN_POS] * 64;
				var packetEnd = i + dataLen + 7;
				if (len > packetEnd && buffer[packetEnd] == this.END_CHAR) {
					var crc = buffer[packetEnd - 1];
					if (Util.sumCheck(buffer, i + this.CC_POS, i + this.CC_POS + dataLen - 1) == crc) {
						return buffer.subarray(i, packetEnd + 1);
					}
				}
			}
		}
	}
	// var up = new UpGw();
	// var validBytes = up.searchValid(dd.bytes, dd.bytes.length);
	// console.log("searchValid =" + Util.bytesToStr(validBytes));


	function DateUtil(dt) {
		this.dt = dt;
	}
	DateUtil.prototype.addHours = function(h) {
		this.dt.setTime(this.dt.setMinutes(this.dt.getMinutes() + 1));
		return this;
	}
	DateUtil.prototype.toStr = function(str) { //author: meizz
		if (str) {
			fmt = str;
		} else {
			fmt = "yyyy-MM-dd HH:mm:ss";
		}
		var o = {
			"M+": this.dt.getMonth() + 1, //月份
			"d+": this.dt.getDate(), //日
			"H+": this.dt.getHours(), //小时
			"m+": this.dt.getMinutes(), //分
			"s+": this.dt.getSeconds(), //秒
			"q+": Math.floor((this.dt.getMonth() + 3) / 3), //季度
			"S": this.dt.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.dt.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o) {
			if (new RegExp("(" + k + ")").test(fmt)) {
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			}
		}
		return fmt;
	}
	// var now = new Date(); //你已知的时间
	// var dt = new DateUtil(now);
	// console.log("dt1=" + dt.toStr());
	// console.log("dt2=" + dt.addHours(1).toStr());